<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>
        车位使用添加+++++++
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
    <script type="text/javascript" th:src="@{/lib/loading/okLoading.js}" ></script>
    <style>
        .imgs {
            display: none;
        }
    </style>
    <!--百度编辑器-->
    <script src="ueditor/ueditor.config.js"></script>
    <script src="ueditor/ueditor.all.min.js"></script>
    <script src="ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>活动管理</cite></a>
              <a><cite>添加活动</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form layui-form-pane" action="" id="add">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <input type="hidden" name="id" value="${param.id}">

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>活动标题
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="title" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"
                                   class="layui-input" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>活动地点
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="place" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"
                                   class="layui-input" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>举办单位
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="hostUnit" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"
                                   class="layui-input" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>开始时间
                        </label>

                        <div class="layui-input-inline">
                            <input class="layui-input" name="startTime" placeholder="开始时间" id="LAY_demorange_s"
                                   value="">
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>结束时间
                        </label>

                        <div class="layui-input-inline">
                            <input class="layui-input" name="endTime" placeholder="结束时间" id="END_demorange_s" value="">
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>状态
                        </label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="有效">
                            <div class="layui-unselect layui-form-radio layui-form-radioed"><i
                                    class="layui-anim layui-icon layui-anim-scaleSpring"></i>
                                <div>有效</div>
                            </div>
                            <input type="radio" name="status" value="2" title="无效" checked="checked">
                            <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>
                                <div>无效</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="link" class="layui-form-label">
                            <span class="x-red">*</span>活动内容
                        </label>
                        <div class="layui-input-inline">
                            <textarea id="content" placeholder="" name="content"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn" type="button" lay-filter="add" lay-submit="">
                            保存
                        </button>
                    </div>
                    <div style="height:100px;"></div>
                </div>
            </div>
        </div>
    </form>
</div>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/js/x-layui.js}" charset="utf-8"></script>
<script th:src="@{/js/jquery.min.js}" charset="UTF-8"></script>
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    // UE.getEditor('content',{initialFrameWidth:750,initialFrameHeight:400,});
</script>
<script>
    if ($("input[name='id']").val() != "") {    //根据id查询数据
        var id = $("input[name='id']").val()
        $.get("/activity/" + id, function (data) {
            console.log(data)
            $("input[name='title']").val(data.data.title);
            $("input[name='place']").val(data.data.place);
            $("input[name='hostUnit']").val(data.data.hostUnit);
            $("input[name='startTime']").val(data.data.startTime);
            $("input[name='endTime']").val(data.data.endTime);
            if (data.data.status == 1) {
                $('input:radio:first').attr('checked', 'true');
            }
            if (data.data.status == 2) {
                $('input:radio:last').attr('checked', 'true');
            }
            // if (data.data.sex == 2) {
            //     $("input[name='sex']").attr("checked", true)
            // }
            // if (data.data.personnelType == 2) {
            //     $("input[name='personnelType']").eq(1).attr("checked", true)
            // }
            // if (data.data.personnelType == 3) {
            //     $("input[name='personnelType']").eq(2).attr("checked", true)
            // }
            // if (data.data.photoPath != "" && data.data.photoPath != null) {
            //     $("#pimages").attr('src', data.data.photoPath);
            //     $("#avatar").val(data.data.photoPath);
            //     $(".imgs").show();
            // }
            // $("textarea[name='remark']").val(data.data.remark);
        })
    }

    layui.use(['laydate', 'element', 'layer', 'form'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        form = layui.form();
        laydate = layui.laydate;//日期插件
        okLoading.close($);
        form.render();

        var start = {
            max: '2099-06-16 23:59:59'
            , choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };

        var end = {
            min: laydate.now()
            , max: '2099-06-16 23:59:59'
            , choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };

        document.getElementById('LAY_demorange_s').onclick = function () {
            start.elem = this;
            laydate(start);
        };

        document.getElementById('END_demorange_s').onclick = function () {
            start.elem = this;
            laydate(start);
        };

        //监听提交
        form.on('submit(add)', function (data) {
            var title=$("input[name='title']").val();
            var place=$("input[name='place']").val();
            var host_unit=$("input[name='host_unit']").val();
            var start_time=$("input[name='start_time']").val();
            var end_time=$("input[name='end_time']").val();
            var content=$("textarea[name='content']").val();
            var status=$("input[name='status']:checked").val();
            var community_id=$('#community_id option:selected') .val();//所属栏目ID
            if(title==""){
                layer.msg('活动标题不能为空',{icon:5,time:2000});return false;
            }
            if(place==""){
                layer.msg('活动地点不能为空',{icon:5,time:2000});return false;
            }
            if(host_unit==""){
                layer.msg('举办单位不能为空',{icon:5,time:2000});return false;
            }
            if(community_id==""){
                layer.msg('所属小区不能为空',{icon:5,time:2000});return false;
            }
            if(start_time==""){
                layer.msg('活动开始时间不能为空',{icon:5,time:2000});return false;
            }
            if(end_time==""){
                layer.msg('活动截止时间不能为空',{icon:5,time:2000});return false;
            }
            if(status==""){
                layer.msg('状态不能为空',{icon:5,time:2000});return false;
            }
            console.log(data)
            var data = data.field;
            $.ajax({
                type: "post",
                url: "add",
                data: data,
                dataType: "json",
                success: function (data) {
                    console.info(data)
                    if (data.data == true) {
                        layer.msg(data.msg, {icon: 6, time: 2000}, function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                        return false;
                    }
                    else {
                        layer.msg(data.msg, {icon: 5, time: 2000});
                        return false;
                    }
                }

            });
            if ($("input[name='id']").val() != "") {
                $.ajax({
                    type: "put",
                    url: "update",
                    data: data,
                    dataType: "json",
                    success: function (data) {
                        console.log(data)
                        if (data.data == true) {
                            layer.msg(data.msg, {icon: 6, time: 2000}, function () {
                                window.parent.location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                return false;
                            });
                        } else {
                            layer.msg("上传失败", {icon: 5, time: 2000});
                            return false;
                        }
                    }
                });
            }

        });

    })
</script>
</body>
</html>